<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 7.3.0">
<link rel="preconnect" href="https://cdn.staticfile.net" crossorigin>
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-round.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-round.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-round.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.staticfile.net/font-awesome/6.6.0/css/all.min.css" integrity="sha256-5eIC48iZUHmSlSUz9XtjRyK2mzQkHScZY1WdMaoz74E=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"wangjiezhe.gitee.io","root":"/","images":"/images","scheme":"Gemini","darkmode":true,"version":"8.21.1","exturl":true,"sidebar":{"position":"left","width_expanded":320,"width_dual_column":240,"display":"post","padding":18,"offset":12},"hljswrap":true,"copycode":{"enable":true,"style":"mac"},"fold":{"enable":false,"height":500},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":true,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":"disqusjs","storage":true,"lazyload":true,"nav":{"disqusjs":{"text":"Disqus","order":1},"giscus":{"text":"GitHub","order":2},"discussbot":{"text":"Telegram","order":3}},"activeClass":"disqusjs"},"stickytabs":false,"motion":{"enable":false,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"top_n_per_article":1,"unescape":false,"preload":false,"style":"flat"}}</script><script src="/js/config.js"></script>

    <meta name="description" content="Rust 的多平台支持还是很好用的">
<meta property="og:type" content="article">
<meta property="og:title" content="为龙芯笔记本交叉编译 Rust">
<meta property="og:url" content="https://wangjiezhe.gitee.io/posts/2024-08-06-Cross-compile-Rust-for-Lemote-Yeeloong-netbook/index.html">
<meta property="og:site_name" content="如鱼饮水">
<meta property="og:description" content="Rust 的多平台支持还是很好用的">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2024-08-06T04:06:47.000Z">
<meta property="article:modified_time" content="2024-12-08T16:54:16.000Z">
<meta property="article:author" content="西风冷香">
<meta property="article:tag" content="Linux">
<meta property="article:tag" content="Gentoo">
<meta property="article:tag" content="Loongson">
<meta property="article:tag" content="龙芯">
<meta property="article:tag" content="Rust">
<meta property="article:tag" content="交叉编译">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://wangjiezhe.gitee.io/posts/2024-08-06-Cross-compile-Rust-for-Lemote-Yeeloong-netbook/">


<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://wangjiezhe.gitee.io/posts/2024-08-06-Cross-compile-Rust-for-Lemote-Yeeloong-netbook/","path":"/posts/2024-08-06-Cross-compile-Rust-for-Lemote-Yeeloong-netbook/","title":"为龙芯笔记本交叉编译 Rust"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>为龙芯笔记本交叉编译 Rust | 如鱼饮水</title>
  
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-48537410-1"></script>
  <script class="next-config" data-name="google_analytics" type="application/json">{"tracking_id":"UA-48537410-1","only_pageview":false,"measure_protocol_api_secret":null}</script>
  <script src="/js/third-party/analytics/google-analytics.js"></script>

  <script src="/js/third-party/analytics/baidu-analytics.js"></script>
  <script async src="https://hm.baidu.com/hm.js?a51d31f349bffa6e3757f7d6fca0c47f"></script>


  <script data-pjax defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{&quot;token&quot;: &quot;a64c9e77fe904641b6e6b04b0e80969c&quot;}'></script>





  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<link rel="alternate" href="/atom.xml" title="如鱼饮水" type="application/atom+xml">
<link rel="alternate" href="/rss2.xml" title="如鱼饮水" type="application/rss+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">如鱼饮水</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">冷暖自知</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li><li class="menu-item menu-item-links"><a href="/links/" rel="section"><i class="fa fa-link fa-fw"></i>友链</a></li><li class="menu-item menu-item-fcircle"><a href="/fcircle/" rel="section"><i class="fa fa-user-group fa-fw"></i>朋友圈</a></li><li class="menu-item menu-item-tools"><a href="/tools/" rel="section"><i class="fa fa-rocket fa-fw"></i>工具</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
      <div class="search-header">
        <span class="search-icon">
          <i class="fa fa-search"></i>
        </span>
        <div class="search-input-container">
          <input autocomplete="off" autocapitalize="off" maxlength="80"
                placeholder="搜索..." spellcheck="false"
                type="search" class="search-input">
        </div>
        <span class="popup-btn-close" role="button">
          <i class="fa fa-times-circle"></i>
        </span>
      </div>
      <div class="search-result-container">
        <div class="search-result-icon">
          <i class="fa fa-spinner fa-pulse fa-5x"></i>
        </div>
      </div>
    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%BA%A4%E5%8F%89%E7%BC%96%E8%AF%91-Rust-%E7%BC%96%E8%AF%91%E5%99%A8"><span class="nav-text">1. 交叉编译 Rust 编译器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E4%BA%A4%E5%8F%89%E7%BC%96%E8%AF%91%E7%94%A8-Rust-%E5%86%99%E7%9A%84%E8%BD%AF%E4%BB%B6"><span class="nav-text">2. 交叉编译用 Rust 写的软件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-tailspin"><span class="nav-text">2.1. tailspin</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-lsd%E3%80%81fd"><span class="nav-text">2.2. lsd、fd</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-git-delta"><span class="nav-text">2.3. git-delta</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-bat"><span class="nav-text">2.4. bat</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-5-ripgrep"><span class="nav-text">2.5. ripgrep</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="西风冷香"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">西风冷香</p>
  <div class="site-description" itemprop="description">某不知名机构不知名数学老师</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">67</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">103</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3dhbmdqaWV6aGU=" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wangjiezhe"><i class="fab fa-github fa-fw"></i></span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOndhbmdqaWV6aGVAZ21haWwuY29t" title="E-Mail → mailto:wangjiezhe@gmail.com"><i class="fa fa-envelope fa-fw"></i></span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly90d2l0dGVyLmNvbS93YW5namllemhl" title="Twitter → https:&#x2F;&#x2F;twitter.com&#x2F;wangjiezhe"><i class="fab fa-twitter fa-fw"></i></span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly90Lm1lL3dhbmdqaWV6aGU=" title="Telegram → https:&#x2F;&#x2F;t.me&#x2F;wangjiezhe"><i class="fab fa-telegram fa-fw"></i></span>
      </span>
  </div>
<div id="time-now">
  <canvas id="canvas" style="width:60%;">当前浏览器不支持canvas，请更换浏览器后再试</canvas>
</div>
<script>
(function(){

  var digit=
    [
      [
        [0,0,1,1,1,0,0],
        [0,1,1,0,1,1,0],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [0,1,1,0,1,1,0],
        [0,0,1,1,1,0,0]
      ],//0
      [
        [0,0,0,1,1,0,0],
        [0,1,1,1,1,0,0],
        [0,0,0,1,1,0,0],
        [0,0,0,1,1,0,0],
        [0,0,0,1,1,0,0],
        [0,0,0,1,1,0,0],
        [0,0,0,1,1,0,0],
        [0,0,0,1,1,0,0],
        [0,0,0,1,1,0,0],
        [1,1,1,1,1,1,1]
      ],//1
      [
        [0,1,1,1,1,1,0],
        [1,1,0,0,0,1,1],
        [0,0,0,0,0,1,1],
        [0,0,0,0,1,1,0],
        [0,0,0,1,1,0,0],
        [0,0,1,1,0,0,0],
        [0,1,1,0,0,0,0],
        [1,1,0,0,0,0,0],
        [1,1,0,0,0,1,1],
        [1,1,1,1,1,1,1]
      ],//2
      [
        [1,1,1,1,1,1,1],
        [0,0,0,0,0,1,1],
        [0,0,0,0,1,1,0],
        [0,0,0,1,1,0,0],
        [0,0,1,1,1,0,0],
        [0,0,0,0,1,1,0],
        [0,0,0,0,0,1,1],
        [0,0,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [0,1,1,1,1,1,0]
      ],//3
      [
        [0,0,0,0,1,1,0],
        [0,0,0,1,1,1,0],
        [0,0,1,1,1,1,0],
        [0,1,1,0,1,1,0],
        [1,1,0,0,1,1,0],
        [1,1,1,1,1,1,1],
        [0,0,0,0,1,1,0],
        [0,0,0,0,1,1,0],
        [0,0,0,0,1,1,0],
        [0,0,0,1,1,1,1]
      ],//4
      [
        [1,1,1,1,1,1,1],
        [1,1,0,0,0,0,0],
        [1,1,0,0,0,0,0],
        [1,1,1,1,1,1,0],
        [0,0,0,0,0,1,1],
        [0,0,0,0,0,1,1],
        [0,0,0,0,0,1,1],
        [0,0,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [0,1,1,1,1,1,0]
      ],//5
      [
        [0,0,0,0,1,1,0],
        [0,0,1,1,0,0,0],
        [0,1,1,0,0,0,0],
        [1,1,0,0,0,0,0],
        [1,1,0,1,1,1,0],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [0,1,1,1,1,1,0]
      ],//6
      [
        [1,1,1,1,1,1,1],
        [1,1,0,0,0,1,1],
        [0,0,0,0,1,1,0],
        [0,0,0,0,1,1,0],
        [0,0,0,1,1,0,0],
        [0,0,0,1,1,0,0],
        [0,0,1,1,0,0,0],
        [0,0,1,1,0,0,0],
        [0,0,1,1,0,0,0],
        [0,0,1,1,0,0,0]
      ],//7
      [
        [0,1,1,1,1,1,0],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [0,1,1,1,1,1,0],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [0,1,1,1,1,1,0]
      ],//8
      [
        [0,1,1,1,1,1,0],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [1,1,0,0,0,1,1],
        [0,1,1,1,0,1,1],
        [0,0,0,0,0,1,1],
        [0,0,0,0,0,1,1],
        [0,0,0,0,1,1,0],
        [0,0,0,1,1,0,0],
        [0,1,1,0,0,0,0]
      ],//9
      [
        [0,0,0,0,0,0,0],
        [0,0,1,1,1,0,0],
        [0,0,1,1,1,0,0],
        [0,0,1,1,1,0,0],
        [0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0],
        [0,0,1,1,1,0,0],
        [0,0,1,1,1,0,0],
        [0,0,1,1,1,0,0],
        [0,0,0,0,0,0,0]
      ]//:
    ];

  var canvas = document.getElementById('canvas');

  if(canvas.getContext){
    var cxt = canvas.getContext('2d');
    //声明canvas的宽高
    var H = 100,W = 700;
    canvas.height = H;
    canvas.width = W;
    cxt.fillStyle = '#f00';
    cxt.fillRect(10,10,50,50);
  
    //存储时间数据
    var data = [];
    //存储运动的小球
    var balls = [];
    //设置粒子半径
    var R = canvas.height/20-1;
    (function(){
      var temp = /(\d)(\d):(\d)(\d):(\d)(\d)/.exec(new Date());
      //存储时间数字，由十位小时、个位小时、冒号、十位分钟、个位分钟、冒号、十位秒钟、个位秒钟这7个数字组成
      data.push(temp[1],temp[2],10,temp[3],temp[4],10,temp[5],temp[6]);
    })();
  
    /*生成点阵数字*/
    function renderDigit(index,num){
      for(var i = 0; i < digit[num].length; i++){
        for(var j = 0; j < digit[num][i].length; j++){
          if(digit[num][i][j] == 1){
            cxt.beginPath();
            cxt.arc(14*(R+2)*index + j*2*(R+1)+(R+1),i*2*(R+1)+(R+1),R,0,2*Math.PI);
            cxt.closePath();
            cxt.fill();
          }
        }
      }
    }
  
    /*更新时钟*/
    function updateDigitTime(){
      var changeNumArray = [];
      var temp = /(\d)(\d):(\d)(\d):(\d)(\d)/.exec(new Date());
      var NewData = [];
      NewData.push(temp[1],temp[2],10,temp[3],temp[4],10,temp[5],temp[6]);
      for(var i = data.length-1; i >=0 ; i--){
        //时间发生变化
        if(NewData[i] !== data[i]){
          //将变化的数字值和在data数组中的索引存储在changeNumArray数组中
          changeNumArray.push(i+'_'+(Number(data[i])+1)%10);
        }
      }
      //增加小球
      for(var i = 0; i< changeNumArray.length; i++){
        addBalls.apply(this,changeNumArray[i].split('_'));
      }
      data = NewData.concat();
    }
  
    /*更新小球状态*/
    function updateBalls(){
      for(var i = 0; i < balls.length; i++){
        balls[i].stepY += balls[i].disY;
        balls[i].x += balls[i].stepX;
        balls[i].y += balls[i].stepY;
        if(balls[i].x > W + R || balls[i].y > H + R){
          balls.splice(i,1);
          i--;
        }
      }
    }
  
    /*增加要运动的小球*/
    function addBalls(index,num){
      var numArray = [1,2,3];
      var colorArray =  ["#3BE","#09C","#A6C","#93C","#9C0","#690","#FB3","#F80","#F44","#C00"];
      for(var i = 0; i < digit[num].length; i++){
        for(var j = 0; j < digit[num][i].length; j++){
          if(digit[num][i][j] == 1){
            var ball = {
              x:14*(R+2)*index + j*2*(R+1)+(R+1),
              y:i*2*(R+1)+(R+1),
              stepX:Math.floor(Math.random() * 4 -2),
              stepY:-2*numArray[Math.floor(Math.random()*numArray.length)],
              color:colorArray[Math.floor(Math.random()*colorArray.length)],
              disY:1
            };
            balls.push(ball);
          }
        }
      }
    }
  
    /*渲染*/
    function render(){
      //重置画布宽度，达到清空画布的效果
      canvas.height = 100;
      //渲染时钟
      for(var i = 0; i < data.length; i++){
        renderDigit(i,data[i]);
      }
      //渲染小球
      for(var i = 0; i < balls.length; i++){
        cxt.beginPath();
        cxt.arc(balls[i].x,balls[i].y,R,0,2*Math.PI);
        cxt.fillStyle = balls[i].color;
        cxt.closePath();
        cxt.fill();
      }
    }
  
    clearInterval(oTimer);
    var oTimer = setInterval(function(){
      //更新时钟
      updateDigitTime();
      //更新小球状态
      updateBalls();
      //渲染
      render();
    },50);
  }

})();
</script>

<div id="site-days"></div>
<script>
  function show_date_time() {
    window.setTimeout("show_date_time()", 1000);
    BirthDay = new Date("2014/01/10 13:29:55");
    today = new Date();
    timeold = (today.getTime() - BirthDay.getTime());
    sectimeold = timeold / 1000;
    secondsold = Math.floor(sectimeold);
    msPerDay = 24 * 60 * 60 * 1000;
    e_daysold = timeold / msPerDay;
    daysold = Math.floor(e_daysold);
    e_hrsold = (e_daysold - daysold) * 24;
    hrsold = setzero(Math.floor(e_hrsold));
    e_minsold = (e_hrsold - hrsold) * 60;
    minsold = setzero(Math.floor((e_hrsold - hrsold) * 60));
    seconds = setzero(Math.floor((e_minsold - minsold) * 60));
    document.getElementById('site-days').innerHTML = "已运行" + daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒";
  }

  function setzero(i) {
    if (i < 10) {
      i = "0" + i
    }
    return i;
  }

  show_date_time();
</script>

        </div>
      </div>
    </div>

    
        <div class="pjax">
        <div class="sidebar-inner sidebar-post-related">
          <div class="animated">
              <div class="links-of-blogroll-title"><i class="fa fa-signs-post fa-fw"></i>
    相关文章
  </div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      <a class="popular-posts-link" href="/posts/2024-07-18-Install-Gentoo-on-Lemote-Yeeloong-netbook/" rel="bookmark">
        <time class="popular-posts-time">2024-07-18</time>
        <br>
      在龙芯笔记本（8089D）上安装 Gentoo
      </a>
    </li>
  </ul>

          </div>
        </div>
        </div>
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wangjiezhe.gitee.io/posts/2024-08-06-Cross-compile-Rust-for-Lemote-Yeeloong-netbook/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="西风冷香">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="如鱼饮水">
      <meta itemprop="description" content="某不知名机构不知名数学老师">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="为龙芯笔记本交叉编译 Rust | 如鱼饮水">
      <meta itemprop="description" content="Rust 的多平台支持还是很好用的">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          为龙芯笔记本交叉编译 Rust
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2024-08-06 12:06:47" itemprop="dateCreated datePublished" datetime="2024-08-06T12:06:47+08:00">2024-08-06</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2024-12-09 00:54:16" itemprop="dateModified" datetime="2024-12-09T00:54:16+08:00">2024-12-09</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Linux/" itemprop="url" rel="index"><span itemprop="name">Linux</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>7.9k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>20 分钟</span>
    </span>
</div>

            <div class="post-description">Rust 的多平台支持还是很好用的</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>在龙芯笔记本上安装好 Gentoo 之后，接下来我要在它上面安装 Rust。主要的原因是我习惯使用的一些命令，比如 <code>fd</code>、<code>rg</code> 和 <code>bat</code> 都需要使用 Rust 编译。</p>
<p>Rust 对 MIPS 提供 Tier 3 级别的支持，并且对 <code>mips64el-unknown-linux-gnuabi64</code> 的 target 提供 host 支持，可以在上面运行 Rust 编译器。因此我们可以直接在龙芯笔记本上安装 Rust，然后在本地编译需要的软件。</p>
<p>不过，直接安装 dev-lang/rust-bin 是不行的，因为 Rust 默认使用 mips64r2 架构进行编译，而龙芯 2F 芯片是基于 mips3 架构的，因此不能直接运行，需要交叉编译 dev-lang/rust 的二进制包。</p>
<h2 id="1-交叉编译-Rust-编译器"><a class="header-anchor" href="#1-交叉编译-Rust-编译器"></a>1. 交叉编译 Rust 编译器</h2>
<p>目前 <span class="exturl" data-url="aHR0cHM6Ly93aWtpLmdlbnRvby5vcmcvd2lraS9Cb290c3RyYXBwaW5nX1J1c3RfdmlhX2Nyb3NzX2NvbXBpbGF0aW9u">Wiki<i class="fa fa-external-link-alt"></i></span> 对于这部分内容的说明已经过时了，根据今年 2 月份 <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2dlbnRvby9nZW50b28vY29tbWl0Lzg2OWE2N2VmY2FlZGJmN2QwOGZlMTYwNTc0NjZmNThhYzFmMjFhODQ=">869a67e<i class="fa fa-external-link-alt"></i></span> 的提交，目前可以直接使用 crossdev 交叉编译 Rust 编译器。</p>
<div class="note danger"><p>20241209 更新：最新的 1.83.0 版本直接交叉编译会失败，原因是 <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3J1c3QtbGFuZy9ydXN0L2NvbW1pdC82ODAzNGY4MzdhMzkzODdlNDlmYzdkN2M1YjA4OGY1MzcyYTExMjdl">68034f8<i class="fa fa-external-link-alt"></i></span>，需要 revert 这个 commit 才可以。</p>
<p>可以下载 <span class="exturl" data-url="aHR0cHM6Ly9naXN0LmdpdGh1Yi5jb20vd2FuZ2ppZXpoZS8xY2VhZTBjZDk0MmFlOWM5N2I5MjljZjg2MTk5MzdlZQ==">Revert-Disable-Zdual-proc-macros-if-the-target-doesn.patch<i class="fa fa-external-link-alt"></i></span> 文件，直接放在 <code>/usr/mips64el-unknown-linux-gnuabi64/etc/portage/patches/dev-lang/rust-1.83.0/</code> 下即可。</p>
</div>
<p>首先在宿主机上安装 Rust。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">## 如果只需要交叉编译 Rust 编译器，直接使用 dev-lang/rust-bin 即可</span></span><br><span class="line"><span class="comment">## 当然也可以使用 dev-lang/rust，不过编译安装需要的时间比较长</span></span><br><span class="line"><span class="comment">##（和编译 GCC 的时间差不多）</span></span><br><span class="line"><span class="comment">## 如果需要交叉编译 Rust 程序，则必须安装 dev-lang/rust</span></span><br><span class="line">emerge -avq dev-lang/rust-bin</span><br></pre></td></tr></table></figure>
<p>根据 ebuild 文件的说明，在进行交叉编译的时候，需要启用 system-bootstrap 的 USE flag，并禁用 system-llvm，还需要启用宿主机的 LLVM target。</p>
<figure class="highlight bash"><figcaption><span>/usr/mips64el-unknown-linux-gnuabi64/etc/portage/package.use/rust</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">dev-lang/rust system-bootstrap -system-llvm</span><br><span class="line">dev-lang/rust LLVM_TARGETS: X86</span><br></pre></td></tr></table></figure>
<p>接下来要把目标架构从 mips64r2 改为 mips3，可以使用 patch：</p>
<figure class="highlight diff"><figcaption><span>/usr/mips64el-unknown-linux-gnuabi64/etc/portage/patches/dev-lang/rust/mips3.patch</span><span class="exturl" data-url="aHR0cHM6Ly9naXN0LmdpdGh1Yi5jb20vd2FuZ2ppZXpoZS83ODZkN2RhNjdkOWZiMmQxMjQzZmQxN2I2OGU1OWYxZQ==">link<i class="fa fa-external-link-alt"></i></span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">diff --git a/compiler/rustc_target/src/spec/targets/mips64el_unknown_linux_gnuabi64.rs b/compiler/rustc_target/src/spec/targets/mips64el_unknown_linux_gnuabi64.rs</span></span><br><span class="line"><span class="comment">index 515473fbabc..fa3c6875964 100644</span></span><br><span class="line"><span class="comment">--- a/compiler/rustc_target/src/spec/targets/mips64el_unknown_linux_gnuabi64.rs</span></span><br><span class="line"><span class="comment">+++ b/compiler/rustc_target/src/spec/targets/mips64el_unknown_linux_gnuabi64.rs</span></span><br><span class="line"><span class="meta">@@ -15,8 +15,8 @@</span> pub fn target() -&gt; Target &#123;</span><br><span class="line">         options: TargetOptions &#123;</span><br><span class="line">             abi: &quot;abi64&quot;.into(),</span><br><span class="line">             // NOTE(mips64r2) matches C toolchain</span><br><span class="line"><span class="deletion">-            cpu: &quot;mips64r2&quot;.into(),</span></span><br><span class="line"><span class="deletion">-            features: &quot;+mips64r2,+xgot&quot;.into(),</span></span><br><span class="line"><span class="addition">+            cpu: &quot;mips3&quot;.into(),</span></span><br><span class="line"><span class="addition">+            features: &quot;+mips3,+xgot&quot;.into(),</span></span><br><span class="line">             max_atomic_width: Some(64),</span><br><span class="line">             mcount: &quot;_mcount&quot;.into(),</span><br></pre></td></tr></table></figure>
<p>也可以使用 env 文件：</p>
<figure class="highlight bash"><figcaption><span>/usr/mips64el-unknown-linux-gnuabi64/etc/portage/env/dev-lang/rust</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="function"><span class="title">post_src_unpack</span></span>() &#123;</span><br><span class="line">  sed -i -e <span class="string">&quot;s/mips64r2/mips3/&quot;</span> \</span><br><span class="line">    <span class="string">&quot;<span class="variable">$&#123;S&#125;</span>&quot;</span>/compiler/rustc_target/src/spec/targets/mips64el_unknown_linux_gnuabi64.rs || die</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>另外还有一点，在编译 Rust 的时候，有一步会有 <code>-DCMAKE_ASM_COMPILER=/usr/bin/mips64el-linux-gnuabi64-gcc</code> 的参数，没有找到原因，不过解决方法很简单，补一个软连接就可以了。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">ln</span> -sv /usr/bin/mips64el-unknown-linux-gnuabi64-gcc /usr/local/bin/mips64el-linux-gnuabi64-gcc</span><br></pre></td></tr></table></figure>
<p>接下来直接安装即可。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mips64el-unknown-linux-gnuabi64-emerge -av dev-lang/rust</span><br></pre></td></tr></table></figure>
<div class="note primary"><p>这里面有两点需要注意：</p>
<ol>
<li><code>sys-libs/glibc</code> 不得使用 <code>-march=loongson2f</code> 编译，否则会提示链接错误；</li>
<li>此时 <code>/usr/mips64el-unknown-linux-gnuabi64/etc/portage/make.conf</code> 中的 CFLAGS 要还原最原始配置（crossdev 安装时默认的即可），不能有 <code>-march</code>、<code>-mtune</code>、<code>-mabi</code> 还有 <code>-Wa,...</code> 的选项。</li>
</ol>
<p>可以通过 <code>package.env</code> 进行配置：</p>
<figure class="highlight bash"><figcaption><span>/usr/mips64el-unknown-linux-gnuabi64/etc/portage/env/embedded</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">CFLAGS=<span class="string">&quot;-O2 -pipe -fomit-frame-pointer&quot;</span></span><br><span class="line">CXXFLAGS=<span class="string">&quot;<span class="variable">$&#123;CFLAGS&#125;</span>&quot;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><figcaption><span>/usr/mips64el-unknown-linux-gnuabi64/etc/portage/env/mips3</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">CFLAGS=<span class="string">&quot;-O2 -march=mips3 -mtune=loongson2f -mabi=64 -Wa,-mfix-loongson2f-nop -pipe&quot;</span></span><br><span class="line">CXXFLAGS=<span class="string">&quot;<span class="variable">$&#123;CFLAGS&#125;</span>&quot;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight markdown"><figcaption><span>/usr/mips64el-unknown-linux-gnuabi64/etc/portage/package.env/rust</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sys-libs/glibc mips3</span><br><span class="line">dev-lang/rust embedded</span><br></pre></td></tr></table></figure></div>
<p>然后把编译好的二进制包复制到龙芯笔记本上</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ssh yeeloong <span class="string">&#x27;mkdir -p /var/cache/binpkgs/dev-lang/rust&#x27;</span></span><br><span class="line">scp /usr/mips64el-unknown-linux-gnuabi64/var/cache/binpkgs/dev-lang/rust/* \</span><br><span class="line">  yeeloong:/var/cache/binpkgs/dev-lang/rust</span><br></pre></td></tr></table></figure>
<p>在龙芯笔记本上：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">## 保持编译时的 USE flag</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">&#x27;dev-lang/rust system-bootstrap -system-llvm&#x27;</span> &gt;&gt; /etc/portage/package.use/rust</span><br><span class="line"><span class="built_in">echo</span> <span class="string">&#x27;dev-lang/rust LLVM_TARGETS: X86&#x27;</span> &gt;&gt; /etc/portage/package.use/rust</span><br><span class="line">emerge -avqk dev-lang/rust</span><br></pre></td></tr></table></figure>
<p>接下来就可以安装常用的几个软件了：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cat</span> &lt;&lt;-<span class="string">EOF &gt;&gt; /etc/portage/package.accept_keywords/rust</span></span><br><span class="line"><span class="string">sys-apps/bat * ~*</span></span><br><span class="line"><span class="string">dev-libs/libgit2 * ~*</span></span><br><span class="line"><span class="string">sys-apps/fd * ~*</span></span><br><span class="line"><span class="string">sys-apps/lsd * ~*</span></span><br><span class="line"><span class="string">sys-apps/ripgrep * ~*</span></span><br><span class="line"><span class="string">dev-util/tailspin * ~*</span></span><br><span class="line"><span class="string">EOF</span></span><br><span class="line"></span><br><span class="line">emerge -avq bat fd ripgrep tailspin lsd</span><br></pre></td></tr></table></figure>
<div class="note info"><p>需要注意的是，在安装 lsd 的时候，<code>CFALGS</code> 的设置不能是 <code>-march=loongson2f</code>，否则会导致编译失败。<br />
使用 <code>-march=mips3</code> 可以正常编译。</p>
<p>这样编译得到的 <code>lsd</code> 执行文件，虽然显示是 mips64r2 架构的：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">file /usr/bin/lsd</span></span><br><span class="line">/usr/bin/lsd: ELF 64-bit LSB pie executable, MIPS, MIPS64 rel2 version 1 (SYSV), dynamically linked, interpreter /lib64/ld.so.1, for GNU/Linux 3.2.0, stripped</span><br></pre></td></tr></table></figure>
<p>但是可以正常运行。</p>
</div>
<h2 id="2-交叉编译用-Rust-写的软件"><a class="header-anchor" href="#2-交叉编译用-Rust-写的软件"></a>2. 交叉编译用 Rust 写的软件</h2>
<p>上面的方法比较简单，但是由于 Rust 编译的速度本身就比较慢，再加上弱鸡的龙芯 CPU，基本上编译一个软件都得一小时起步：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">qlop -v bat fd ripgrep tailspin lsd</span></span><br><span class="line">2024-07-12T12:04:23 &gt;&gt;&gt; sys-apps/bat-0.24.0-r1: 2:30:33</span><br><span class="line">2024-07-12T15:22:19 &gt;&gt;&gt; sys-apps/ripgrep-14.1.0-r1: 1:10:49</span><br><span class="line">2024-07-12T16:58:42 &gt;&gt;&gt; sys-apps/fd-10.1.0: 1:01:34</span><br><span class="line">2024-07-12T18:41:51 &gt;&gt;&gt; dev-util/tailspin-3.0.1: 2:05:39</span><br><span class="line">2024-07-13T11:48:53 &gt;&gt;&gt; sys-apps/lsd-1.1.2-r1: 1:54:52</span><br></pre></td></tr></table></figure>
<p>因此，也可以选择直接在宿主机上交叉编译所需要的软件，不过相对来说比较麻烦，需要处理的问题比较多。</p>
<p>根据 <span class="exturl" data-url="aHR0cHM6Ly9idWdzLmdlbnRvby5vcmcvNjc5ODc4">Bug 679878<i class="fa fa-external-link-alt"></i></span> 的说明，目前直接通过 crossdev 直接编译 Rust 编写的软件还有一些问题没有解决。实测也是如此，大部分软件都需要一些 hacking 才能成功交叉编译安装。</p>
<p>首先在宿主机上安装 rust：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">## 这是因为之前已经安装了 `rust-bin` 和 `llvm`，否则不选也可以。</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">&#x27;dev-lang/rust system-bootstrap system-llvm&#x27;</span> &gt;&gt; /etc/portage/package.use/rust</span><br><span class="line"></span><br><span class="line"><span class="comment">## 启用 MIPS 交叉编译。</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">&#x27;dev-lang/rust LLVM_TARGETS: Mips&#x27;</span> &gt;&gt; /etc/portage/package.use/rust</span><br><span class="line"></span><br><span class="line"><span class="comment">## 进行 Rust 编程所需要的一些工具</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">&#x27;dev-lang/rust rust-analyzer rustfmt clippy rust-src&#x27;</span> &gt;&gt; /etc/portage/package.use/rust</span><br><span class="line"></span><br><span class="line"><span class="comment">## 把前面的 mips3 补丁复制过来</span></span><br><span class="line"><span class="built_in">mkdir</span> -p /etc/portage/patches/dev-lang/rust/</span><br><span class="line"><span class="built_in">cp</span> /usr/mips64el-unknown-linux-gnuabi64/etc/portage/patches/dev-lang/rust/mips3.patch \</span><br><span class="line">  /etc/portage/patches/dev-lang/rust/mips3.patch</span><br><span class="line"><span class="comment">## 或者</span></span><br><span class="line"><span class="built_in">mkdir</span> -p /etc/portage/env/dev-lang/</span><br><span class="line"><span class="built_in">cp</span> /usr/mips64el-unknown-linux-gnuabi64/etc/portage/env/dev-lang/rust \</span><br><span class="line">  /etc/portage/env/dev-lang/rust</span><br><span class="line"></span><br><span class="line">emerge -avq rust</span><br></pre></td></tr></table></figure>
<p>然后安装 rust-std。首先需要将 sys-devel/rust-std 链接到 crossdev 的仓库中：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">ln</span> -sv /var/db/repos/gentoo/sys-devel/rust-std \</span><br><span class="line">  /var/db/repos/crossdev/cross-mips64el-unknown-linux-gnuabi64</span><br></pre></td></tr></table></figure>
<p>跟前面类似，这里也要使用 mips3 编译 rust-std，而且需要在编译时禁止下载 LLVM：</p>
<figure class="highlight bash"><figcaption><span>/etc/portage/env/cross-mips64el-unknown-linux-gnuabi64/rust-std</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="function"><span class="title">post_src_unpack</span></span>() &#123;</span><br><span class="line">  sed -i -e <span class="string">&quot;s/mips64r2/mips3/&quot;</span> \</span><br><span class="line">    <span class="string">&quot;<span class="variable">$&#123;S&#125;</span>&quot;</span>/compiler/rustc_target/src/spec/targets/mips64el_unknown_linux_gnuabi64.rs || die</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="function"><span class="title">post_src_configure</span></span>() &#123;</span><br><span class="line">  sed -i -e <span class="string">&quot;1i\</span></span><br><span class="line"><span class="string">[llvm]\n\</span></span><br><span class="line"><span class="string">download-ci-llvm = false&quot;</span> \</span><br><span class="line">  <span class="string">&quot;<span class="variable">$&#123;S&#125;</span>&quot;</span>/config.toml || die</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>然后就可以安装了。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">emerge -avq cross-mips64el-unknown-linux-gnuabi64/rust-std</span><br></pre></td></tr></table></figure>
<p>接下来，我们就可以交叉编译所需要的软件了。</p>
<h3 id="2-1-tailspin"><a class="header-anchor" href="#2-1-tailspin"></a>2.1. tailspin</h3>
<p>直接安装即可。</p>
<h3 id="2-2-lsd、fd"><a class="header-anchor" href="#2-2-lsd、fd"></a>2.2. lsd、fd</h3>
<p>lsd、fd 都可以成功编译，不过需要禁用 lto：</p>
<figure class="highlight bash"><figcaption><span>/usr/mips64el-unknown-linux-gnuabi64/etc/portage/env/sys-apps/&#123;lsd,fd&#125;</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="function"><span class="title">post_src_prepare</span></span>() &#123;</span><br><span class="line">  sed -i -e <span class="string">&#x27;/^lto/s:true:false:&#x27;</span> Cargo.toml || die</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>而且 lsd 不能使用 <code>-march=loongson2f</code> 编译，要改为使用 <code>-march=mips3</code> 才可以：</p>
<figure class="highlight markdown"><figcaption><span>/usr/mips64el-unknown-linux-gnuabi64/etc/portage/package.env/lsd</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sys-apps/lsd mips3</span><br></pre></td></tr></table></figure>
<h3 id="2-3-git-delta"><a class="header-anchor" href="#2-3-git-delta"></a>2.3. git-delta</h3>
<p>git-delta 需要禁用 RUSTONIG_DYNAMIC_LIBONIG：</p>
<figure class="highlight bash"><figcaption><span>/usr/mips64el-unknown-linux-gnuabi64/etc/portage/env/sys-apps/git-delta</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="function"><span class="title">post_src_configure</span></span>() &#123;</span><br><span class="line">  <span class="built_in">export</span> RUSTONIG_SYSTEM_LIBONIG=0</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>另外，它和 lsd 一样，也不能用 <code>-march=loongson2f</code> 编译：</p>
<figure class="highlight markdown"><figcaption><span>/usr/mips64el-unknown-linux-gnuabi64/etc/portage/package.env/git-delta</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sys-apps/git-delta mips3</span><br></pre></td></tr></table></figure>
<h3 id="2-4-bat"><a class="header-anchor" href="#2-4-bat"></a>2.4. bat</h3>
<p>bat 需要同时禁用 lto 和 RUSTONIG_DYNAMIC_LIBONIG：</p>
<figure class="highlight bash"><figcaption><span>/usr/mips64el-unknown-linux-gnuabi64/etc/portage/env/sys-apps/bat</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="function"><span class="title">post_src_prepare</span></span>() &#123;</span><br><span class="line">  sed -i -e <span class="string">&#x27;/^lto/s:true:false:&#x27;</span> Cargo.toml || die</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="function"><span class="title">post_src_configure</span></span>() &#123;</span><br><span class="line">  <span class="built_in">export</span> RUSTONIG_SYSTEM_LIBONIG=0</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="2-5-ripgrep"><a class="header-anchor" href="#2-5-ripgrep"></a>2.5. ripgrep</h3>
<p>ripgrep 需要使用 <span class="exturl" data-url="aHR0cHM6Ly93aWtpLmdlbnRvby5vcmcvd2lraS9FbWJlZGRlZF9IYW5kYm9vay9HZW5lcmFsL0NvbXBpbGluZ193aXRoX1FFTVVfdXNlcl9jaHJvb3Q=">QEMU User Mode Emulation<i class="fa fa-external-link-alt"></i></span>，因为在安装的时候直接运行了 <code>rg</code> 命令。</p>
<p>按照 Wiki 中的指示，使用 <code>USE=static-usr</code> 和 <code>QEMU_USER_TARGETS：mips64el</code> 安装好 qemu 之后，<s>启用 binfmt 服务：</s></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">## 配置 QEMU_LD_PREFIX</span></span><br><span class="line"><span class="comment"># mkdir /usr/gnemul</span></span><br><span class="line"><span class="comment"># ln -sv /usr/mips64el-unknown-linux-gnuabi64 /usr/gnemul/qemu-mips64el</span></span><br><span class="line"><span class="comment">## 启动 binfmt 服务</span></span><br><span class="line"><span class="comment"># rc-service qemu-binfmt start</span></span><br></pre></td></tr></table></figure>
<p><s>也可以直接</s> 使用 <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3dhbmdqaWV6aGUvcWVtdS13cmFwcGVy">wrapper<i class="fa fa-external-link-alt"></i></span>，然后手动配置 binfmt：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">echo</span> <span class="string">&#x27;:qemu-mips64el:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-wrapper-hard-loongson-n64:OC&#x27;</span> &gt; /proc/sys/fs/binfmt_misc/register</span><br></pre></td></tr></table></figure>
<hr />
<p>最后对比一下在宿主上交叉编译所需要的时间：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">2024-08-06T18:26:40 &gt;&gt;&gt; sys-apps/lsd-1.1.2-r1: 33s</span><br><span class="line">2024-08-06T18:34:39 &gt;&gt;&gt; sys-apps/fd-10.1.0: 25s</span><br><span class="line">2024-08-06T18:40:08 &gt;&gt;&gt; sys-apps/ripgrep-14.1.0-r1: 20s</span><br><span class="line">2024-08-06T19:50:18 &gt;&gt;&gt; sys-apps/bat-0.24.0-r1: 49s</span><br><span class="line">2024-08-06T20:16:21 &gt;&gt;&gt; dev-util/tailspin-3.0.1: 23s</span><br><span class="line">2024-08-06T20:19:06 &gt;&gt;&gt; dev-util/git-delta-0.16.5: 31s</span><br><span class="line">2024-08-17T13:24:54 &gt;&gt;&gt; sys-apps/ripgrep-all-0.10.6: 59s</span><br></pre></td></tr></table></figure>

    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>西风冷香
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://wangjiezhe.gitee.io/posts/2024-08-06-Cross-compile-Rust-for-Lemote-Yeeloong-netbook/" title="为龙芯笔记本交叉编译 Rust">https://wangjiezhe.gitee.io/posts/2024-08-06-Cross-compile-Rust-for-Lemote-Yeeloong-netbook/</a>
  </li>
  <li class="post-copyright-license">
      <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzQuMC9kZWVkLnpo"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="followme">
  <span>欢迎关注我的其它发布渠道</span>

  <div class="social-list">

      <div class="social-item">
          <span class="social-link">
            <span class="icon">
              <i class="fab fa-weixin"></i>
            </span>

            <span class="label">WeChat</span>
          </span>

          <img class="social-item-img" src="/images/wechat_channel.jpg">
      </div>

      <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
      </div>
  </div>
</div>

          <div class="post-tags">
              <a href="/tags/Linux/" rel="tag"><i class="fa fa-tag"></i> Linux</a>
              <a href="/tags/Gentoo/" rel="tag"><i class="fa fa-tag"></i> Gentoo</a>
              <a href="/tags/Loongson/" rel="tag"><i class="fa fa-tag"></i> Loongson</a>
              <a href="/tags/%E9%BE%99%E8%8A%AF/" rel="tag"><i class="fa fa-tag"></i> 龙芯</a>
              <a href="/tags/Rust/" rel="tag"><i class="fa fa-tag"></i> Rust</a>
              <a href="/tags/%E4%BA%A4%E5%8F%89%E7%BC%96%E8%AF%91/" rel="tag"><i class="fa fa-tag"></i> 交叉编译</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/posts/2024-08-05-Install-driver-for-Lenovo-M7600D-printer/" rel="prev" title="为龙芯笔记本安装联想 M7600D 打印机">
                  <i class="fa fa-angle-left"></i> 为龙芯笔记本安装联想 M7600D 打印机
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/posts/2024-08-11-He-Qie-301-2/" rel="next" title="何切301练习 031~060">
                  何切301练习 031~060 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






      <div class="tabs tabs-comment">
        <ul class="nav-tabs">
            <li class="tab"><a href="#comment-disqusjs">Disqus</a></li>
            <li class="tab"><a href="#comment-giscus">GitHub</a></li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane disqusjs" id="comment-disqusjs">
              
  <div class="comments disqusjs-container">
    <noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
  </div>
  
            </div>
            <div class="tab-pane giscus" id="comment-giscus">
              
  
  <div class="comments giscus-container">
  </div>
  
  
            </div>
        </div>
      </div>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="beian"><span class="exturl" data-url="aHR0cHM6Ly9iZWlhbi5taWl0Lmdvdi5jbg=="><nopangu>冀ICP备2024063721号-1</nopangu> </span>
      <img src="/images/gongan.png" alt=""><span class="exturl" data-url="aHR0cHM6Ly9iZWlhbi5tcHMuZ292LmNuLyMvcXVlcnkvd2ViU2VhcmNoP2NvZGU9MTMwOTAyMDIwMDA3MTY="><nopangu>冀公网安备13090202000716号</nopangu> </span>
  </div>
  <div class="copyright">
    &copy; 2014 – 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">西风冷香</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">223k</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>
  <div class="powered-by">由 <span class="exturl" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & <span class="exturl" data-url="aHR0cHM6Ly90aGVtZS1uZXh0LmpzLm9yZw==">NexT.Gemini</span> 强力驱动
  </div>

<div class="blog-links">
    <span class="post-meta-item moe">
      <span>
        <img src="/images/icp-moe.png" style="width:auto;height:16px;" alt="">
      </span>
      <span><span class="exturl" data-url="aHR0cHM6Ly9pY3AuZ292Lm1vZS8/a2V5d29yZD0yMDI0ODE5MQ=="><nopangu>萌ICP备20248191号</nopangu></span>
      </span>
    </span>
    <span class="post-meta-item travel-moe">
      <span><span class="exturl" data-url="aHR0cHM6Ly90cmF2ZWwubW9lL2dvLmh0bWw/dHJhdmVsPW9u"><img src="/images/travel-moe.png" style="width:auto;height:18px" title="异次元之旅-跃迁-我们一起去萌站成员的星球旅行吧！"> 异次元之旅🚀</span>
      </span>
    </span>
    <span class="post-meta-item foreverblog"><span class="exturl" data-url="aHR0cHM6Ly93d3cuZm9yZXZlcmJsb2cuY24vYmxvZy8yMDkyLmh0bWw="><img src="/images/foreverblog.png" style="width:auto;height:16px;" alt="Forever Blog"></span>
    </span>
    <span class="post-meta-item wormhole"><span class="exturl" data-url="aHR0cHM6Ly93d3cuZm9yZXZlcmJsb2cuY24vZ28uaHRtbA=="><img src="/images/wormhole.gif" style="width:auto;height:24px;" alt="" title="穿梭虫洞-随机访问十年之约友链博客"></span>
    </span>
    <span class="post-meta-item travelling"><span class="exturl" data-url="aHR0cHM6Ly93d3cudHJhdmVsbGluZ3MuY24vZ28uaHRtbA=="><img src="/images/travelling.png" alt="开往-友链接力" height="18"></span>
    </span>
  
</div>

<script>
function checkWebp(callback) {
  var img = new Image();
  img.onload = function () { callback((img.width > 0) && (img.height > 0)); };
  img.onerror = function () { callback(false); };
  img.src = '';
}
function showImage(useWebp) {
  var imgs = [].slice.call(document.querySelectorAll('img'));
  imgs.forEach(function (e) {
    if ((useWebp) && !e.classList.contains('nowebp')) {
      var src = e.getAttribute('data-src')
      if (src !== null) {
        src = src.replace(/\.jpg$/, '.webp').replace(/\.jpeg$/, '.webp').replace(/\.png$/, '.webp').replace(/\.gif$/, '.webp');
        e.setAttribute('data-src', src);
      }
      src = e.getAttribute('src')
      if (src !== null) {
        src = src.replace(/\.jpg$/, '.webp').replace(/\.jpeg$/, '.webp').replace(/\.png$/, '.webp').replace(/\.gif$/, '.webp');
        e.setAttribute('src', src);
      }
    }
  });
}
</script>
<script data-pjax async>
checkWebp(showImage);
</script>


    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdn.staticfile.net/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdn.staticfile.net/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdn.staticfile.net/medium-zoom/1.1.0/medium-zoom.min.js" integrity="sha256-ZgMyDAIYDYGxbcpJcfUnYwNevG/xi9OHKaR/8GK+jWc=" crossorigin="anonymous"></script>
  <script src="https://cdn.staticfile.net/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/sidebar.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdn.staticfile.net/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>

  <script class="next-config" data-name="pdf" type="application/json">{"object_url":{"url":"https://cdn.staticfile.net/pdfobject/2.3.0/pdfobject.min.js","integrity":"sha256-JJZNsid68vnh3/zyj0lY9BN5ynxVX/12XgOa1TlaYN0="},"url":"/lib/pdf/web/viewer.html"}</script>
  <script src="/js/third-party/tags/pdf.js"></script>






  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  <script src="https://cdn.staticfile.net/firebase/10.14.1/firebase-app-compat.js" integrity="sha256-KsPwUaqMNX8FDBi2qNV4Z/We2FthlJrPIRQhOVgfXMQ=" crossorigin="anonymous"></script>
  <script src="https://cdn.staticfile.net/firebase/10.14.1/firebase-firestore-compat.js" integrity="sha256-oPdfryMK6T4WGGJbidMkl/7TIOrnkCJ8BqrOT8En2a4=" crossorigin="anonymous"></script>
  <script class="next-config" data-name="firestore" type="application/json">{"enable":true,"collection":"articles","apiKey":"AIzaSyD0AfWHrmFoKgV1x4srPQDN7rGpGclK7J4","projectId":"visitors-of-blog"}</script>
  <script src="/js/third-party/statistics/firestore.js"></script>



  

  <script class="next-config" data-name="enableMath" type="application/json">false</script><link rel="stylesheet" href="https://cdn.staticfile.net/KaTeX/0.16.9/katex.min.css" integrity="sha256-UF1fgpAiu3tPJN/uCqEUHNe7pnr+QR0SQDNfgglgtcM=" crossorigin="anonymous">
  <script class="next-config" data-name="katex" type="application/json">{"copy_tex_js":{"url":"https://cdn.staticfile.net/KaTeX/0.16.9/contrib/copy-tex.min.js","integrity":"sha256-Us54+rSGDSTvIhKKUs4kygE2ipA0RXpWWh0/zLqw3bs="}}</script>
  <script src="/js/third-party/math/katex.js"></script>


  <script src="https://cdn.staticfile.net/quicklink/2.3.0/quicklink.umd.js" integrity="sha256-yvJQOINiH9fWemHn0vCA5lsHWJaHs6/ZmO+1Ft04SvM=" crossorigin="anonymous"></script>
  <script class="next-config" data-name="quicklink" type="application/json">{"enable":true,"home":false,"archive":false,"delay":true,"timeout":3000,"priority":true,"url":"https://wangjiezhe.gitee.io/posts/2024-08-06-Cross-compile-Rust-for-Lemote-Yeeloong-netbook/"}</script>
  <script src="/js/third-party/quicklink.js"></script>
<script class="next-config" data-name="giscus" type="application/json">{"enable":true,"repo":"wangjiezhe/wangjiezhe.github.io","repo_id":"MDEwOlJlcG9zaXRvcnkxNTc4OTE0Ng==","category":"Announcements","category_id":"DIC_kwDOAPDsWs4Cdwtf","mapping":"og:title","strict":1,"reactions_enabled":1,"emit_metadata":1,"theme":"preferred_color_scheme","lang":"zh-CN","crossorigin":"anonymous","input_position":"top","loading":"lazy"}</script>

<script>
document.addEventListener('page:loaded', () => {
  if (!CONFIG.page.comments) return;

  NexT.utils.loadComments('.giscus-container')
    .then(() => NexT.utils.getScript('https://giscus.app/client.js', {
      attributes: {
        async                   : true,
        crossOrigin             : 'anonymous',
        'data-repo'             : CONFIG.giscus.repo,
        'data-repo-id'          : CONFIG.giscus.repo_id,
        'data-category'         : CONFIG.giscus.category,
        'data-category-id'      : CONFIG.giscus.category_id,
        'data-mapping'          : CONFIG.giscus.mapping,
        'data-strict'           : CONFIG.giscus.strict,
        'data-reactions-enabled': CONFIG.giscus.reactions_enabled,
        'data-emit-metadata'    : CONFIG.giscus.emit_metadata,
        'data-theme'            : CONFIG.giscus.theme,
        'data-lang'             : CONFIG.giscus.lang,
        'data-input-position'   : CONFIG.giscus.input_position,
        'data-loading'          : CONFIG.giscus.loading
      },
      parentNode: document.querySelector('.giscus-container')
    }));
});
</script>
<link rel="stylesheet" href="https://cdn.staticfile.net/disqusjs/3.0.2/styles/disqusjs.css" integrity="sha256-71XarXwNr1Td27HmZI9zjY+rMzRdush6/glo6VFXp7o=" crossorigin="anonymous">

<script class="next-config" data-name="disqusjs" type="application/json">{"enable":true,"api":"https://disqusjs.wangjiezhe.com/","apikey":"ENTX2OPfWXIYJpFIZ1WVpYt4F0Ri0PLUELMOCbM8HHIX9C9BqEbkBZWmK7lqKj7F","shortname":"wangjiezhe","js":{"url":"https://cdn.staticfile.net/disqusjs/3.0.2/disqusjs.es2015.umd.min.js","integrity":"sha256-okP99ZQKVpIy7+NogAMpGlIQzJa9XKXhIJcFgdju5bU="}}</script>
<script src="/js/third-party/comments/disqusjs.js"></script>



  <script async src="/js/cursor/fireworks.min.js" integrity="sha256-NVjeK0/Qni9W+mCWpzpw6IZTieyhLZJ5Kj4hdFjqSQc=" crossorigin="anonymous"></script>



<script src="/live2dw/lib/L2Dwidget.min.js?02887b17076210cf9f6ed81f0eed64e3"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/mikoto.model.json"},"display":{"position":"left"},"mobile":{"show":false},"log":false});</script></body>
</html>
